package com.cctc.juc.demo.Bitc.Tmp.ADemo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ESingleThreadExecutorDemo {

    // 效果 4： A~Z 任务按照顺序、串行化执行。

    private static final ExecutorService service = Executors.newSingleThreadExecutor();

    public static void main(String[] args) {
        for (char ch = 'A'; ch <= 'Z'; ch++) {
            final String taskName = String.valueOf(ch);
            service.execute(() -> {
                System.out.print(taskName + " ");
            });
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        service.shutdown();
    }

}
